home *** CD-ROM | disk | FTP | other *** search
/ Freelog 22 / freelog 22.iso / Prog / Djgpp / GPC2952B.ZIP / doc / gpc / docdemos / pointerarithmeticdemo.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2001-02-09  |  396 b   |  25 lines

  1. program PointerArithmeticDemo;
  2. var
  3.   a: array [1 .. 7] of Char;
  4.   p, q: ^Char;
  5.   i: Integer;
  6.  
  7. {$X+} { We need extended syntax for pointer arithmetic }
  8.  
  9. begin
  10.   for p := @A [1] to @A [7] do
  11.     p^ := 'x';
  12.  
  13.   p := @A [ 7 ];
  14.   q := @A [ 3 ];
  15.   while p > q do
  16.     begin
  17.       p^ := 'y';
  18.       Dec (p)
  19.     end;
  20.  
  21.   p := @A [7];
  22.   q := @A [3];
  23.   i := q - p;    { yields 4 }
  24. end.
  25.